//
//  ViewController.m
//  技术点总结
//
//  Created by tianlong on 2018/6/4.
//  Copyright © 2018年 tianlong. All rights reserved.
//

#import "ViewController.h"
#import "PKTestTableView.h"
#import "Masonry.h"
#import "Person.h"
#import "TestStringVC.h"
#import "TestArrayVC.h"
#import "TestCustoObjectVC.h"
#import "TestArrayTransmitVC.h"
#import "TestRetainCountVC.h"
#import "TestMemoryVC.h"

@interface ViewController ()
@property (strong, nonatomic) PKTestTableView *table;
@property (strong, nonatomic) Person *p1;
@property (strong, nonatomic) Person *p;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self addTestModel];
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [self logP];
}

- (void)logP {
    if (self.p) {
        NSLog(@"\n修饰符：stong   =:     p  = %p  p_指针地址  = %p    p.name  = %@",self.p,&_p,self.p.name);
    }
    
    if (self.p1) {
        NSLog(@"\n修饰符：stong   =:     p1 = %p  p1_指针地址 = %p    p1.name = %@",self.p1,&_p1,self.p1.name);
    }
}

- (void)addTestModel {

    NSMutableArray *dataM = [NSMutableArray array];
    
    //strong和copy修饰字符串
    {
        PKTestModel *model = [[PKTestModel alloc] initWithTitle:@"strong和copy修饰字符串" action:@selector(test_string) target:self];
        model.subtitle = @"赋值方式：=，copy，mutableCopy";
        [dataM addObject:model];
    }
    
    //strong和copy修饰自定义对象
    {
        PKTestModel *model = [[PKTestModel alloc] initWithTitle:@"自定义对象测试" action:@selector(test_customObject) target:self];
        model.subtitle = @"赋值方式：=，copy，mutableCopy";
        [dataM addObject:model];
    }
   
    //数组赋值（方式 = ， copy ， mutableCopy）
    {
        PKTestModel *model = [[PKTestModel alloc] initWithTitle:@"数组赋值" action:@selector(test_array_assignment) target:self];
        model.subtitle = @"方式 = ， copy ， mutableCopy";
        [dataM addObject:model];
    }
    
    //数组的传递
    {
        PKTestModel *model = [[PKTestModel alloc] initWithTitle:@"数组的传递" action:@selector(test_array) target:self];
        [dataM addObject:model];
    }
    
    //copy和strong的引用计数器
    {
        PKTestModel *model = [[PKTestModel alloc] initWithTitle:@"copy和strong的引用计数器" action:@selector(test_retainCount) target:self];
        [dataM addObject:model];
    }
    
    //测试通过内存地址修改内存中的值
    {
        PKTestModel *model = [[PKTestModel alloc] initWithTitle:@"通过内存地址修改内存中的值" action:@selector(test_memory) target:self];
        [dataM addObject:model];
    }
    
    
    if (!_table) {
        self.table = [[PKTestTableView alloc] initWithDataSource:dataM];
        self.table.frame = self.view.bounds;
        [self.view addSubview:self.table];
    }
}

#pragma mark - 测试通过内存地址修改内存中的值
- (void)test_memory {
    TestMemoryVC *vc = [[TestMemoryVC alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark - copy和strong的引用计数器
- (void)test_retainCount {
    TestRetainCountVC *vc = [[TestRetainCountVC alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}


#pragma mark - 数组的传递
- (void)test_array {
    TestArrayTransmitVC *vc = [[TestArrayTransmitVC alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark - 测试自定义对象
- (void)test_customObject {
    TestCustoObjectVC *vc = [[TestCustoObjectVC alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark - 测试字符串
- (void)test_string {
    TestStringVC *vc = [[TestStringVC alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark - 数组赋值（方式 = ， copy ， mutableCopy）
- (void)test_array_assignment {
    TestArrayVC *vc = [[TestArrayVC alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

@end
